package com.wdciti.sccp.iot.utils;

import com.wdciti.sccp.iot.springvertx.annotation.VerticleBean;
import com.wdciti.sccp.iot.springvertx.protocols.mqtt.MqttHeader;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.DeliveryOptions;

/**
 * @author by early
 */
//@Slf4j
//@VerticleBean(isWorker = true)
public class testMqttMsgVerticle extends AbstractVerticle {

    @Override
    public void start() {
        vertx.eventBus().<Buffer>consumer("ely://simpleMqtt/in").handler(msg -> {
            System.out.println(msg.body().toString());
            MqttHeader header = MqttHeader.buildFrom(msg.headers());
            System.out.println(header);

            header.setTopicName("aaa");
            DeliveryOptions options = new DeliveryOptions();
            options.setHeaders(header.addMqttHeader(options.getHeaders()));
            Buffer buf = Buffer.buffer("Hello MQTT! " + msg.body());
            vertx.eventBus().send("ely://simpleMqtt/out", buf, options);
        });
    }

}
